{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e05daaca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[12, 3, 4, 5]\n",
      "[12, 3, 4, 5, 12, 3, 4, 5]\n",
      "<class 'list'> [12, 3, 45, 3] 4\n",
      "<class 'set'> {33452, 23452, 234526, 63} 4\n",
      "<class 'tuple'> (1234, 5, 432546) 3\n",
      "<class 'dict'> {123: 132, 342: 4123, 24534: 412, 'key': 'value'} 4\n",
      "<class 'str'> yangyanyun 10\n",
      "<class 'set'> {3, 12, 45} 3\n",
      "<class 'set'> {432546, 1234, 5} 3\n",
      "<class 'set'> {123, 'key', 24534, 342} 4\n",
      "<class 'set'> {'u', 'n', 'g', 'y', 'a'} 5\n",
      "jhfgdsa\n",
      "sdgfhj\n",
      "asdgfh\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = [12,3,4,5]\n",
    "print(a)\n",
    "a *= 2                \n",
    "print(a)\n",
    "\n",
    "l = [12,3,45,3]\n",
    "t = (1234,5,432546)\n",
    "s = {23452,234526,33452,63}\n",
    "d = {123:132,342:4123,24534:412}\n",
    "d[\"key\"] = \"value\"\n",
    "st = \"yangyanyun\"\n",
    "print(type(l),l,len(l)) # type(l) -> string,len(l) -> int\n",
    "print(type(s),s,len(s)) # set(),tuple(),list()\n",
    "print(type(t),t,len(t))\n",
    "print(type(d),d,len(d))\n",
    "print(type(st),st,len(st))\n",
    "s = set(l)\n",
    "print(type(s),s,len(s))\n",
    "s = set(t)\n",
    "print(type(s),s,len(s))\n",
    "s = set(d)\n",
    "print(type(s),s,len(s))\n",
    "s = set(st)\n",
    "print(type(s),s,len(s))\n",
    "ss = \"asdgfhj\\n\"\n",
    "ss = ss[:-2]\n",
    "print(ss[::-1])\n",
    "print(ss[1:])\n",
    "print(ss[:-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "01ffd895",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13 7 30 3.3333333333333335 1 1000 3\n",
      "[2, 34, 54, 2435] operator_symbol_0710.ipynb None\n",
      "xxxxxx\n",
      "init\n",
      "['dfg', 4356]\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "算数运算符 只能number类型\n",
    "以下假设变量a为10，变量b为20：\n",
    "+\t加 - 两个对象相加\ta + b 输出结果 30\n",
    "-\t减 - 得到负数或是一个数减去另一个数\ta - b 输出结果 -10\n",
    "*\t乘 - 两个数相乘或是返回一个被重复若干次的字符串\ta * b 输出结果 200\n",
    "/\t除 - x除以y\tb / a 输出结果 2\n",
    "%\t取模 - 返回除法的余数\tb % a 输出结果 0\n",
    "**\t幂 - 返回x的y次幂\ta**b 为10的20次方， 输出结果 100000000000000000000\n",
    "//\t取整除 - 返回商的整数部分\t9//2 输出结果 4 , 9.0//2.0 输出结果 4\n",
    "'''\n",
    "a = 10\n",
    "b = 3\n",
    "print(a+b, a - b, a*b, a/b, a % b, a ** b, a // b)\n",
    "l = [2,34,54]\n",
    "print(l,\"operator_symbol_0710.ipynb\",l.append(2435)) # l.append(234)\n",
    "\n",
    "class mylist(object):\n",
    "    __slots__ = (\"__array\") #tuple\n",
    "    def __init__(self):\n",
    "        print(\"init\")\n",
    "        self.__array = []\n",
    "    def __new__(cls):\n",
    "        print(\"xxxxxx\")\n",
    "        return super().__new__(cls)\n",
    "    def __str__(self): #print(对象)\n",
    "        return \"{}\".format(self.__array)\n",
    "    def append(self, val):\n",
    "        self.__array.append(val)\n",
    "ll = mylist()\n",
    "ll.append('dfg')\n",
    "ll.append(4356)\n",
    "print(ll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "cc901d13",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False False <class 'bool'>\n",
      "True False True False True\n",
      "False True True False True False\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "比较运算符,False Ture；Number、List（从左往右按顺序比较，有结果就能返回，不一定全部比较完）可用\n",
    "以下假设变量a为10，变量b为20：\n",
    "==\t等于 - 比较对象是否相等\t(a == b) 返回 False。\n",
    "!=\t不等于 - 比较两个对象是否不相等\t(a != b) 返回 True.\n",
    "<>\t不等于 - 比较两个对象是否不相等\t(a <> b) 返回 True。这个运算符类似 != ，最好不用。\n",
    ">\t大于 - 返回x是否大于y\t(a > b) 返回 False。\n",
    "<\t小于 - 返回x是否小于y。所有比较运算符返回1表示真，返回0表示假。这分别与特殊的变量True和False等价。注意，这些变量名的大写。\t(a < b) 返回 True。\n",
    ">=\t大于等于 - 返回x是否大于等于y。\t(a >= b) 返回 False。\n",
    "<=\t小于等于 - 返回x是否小于等于y。\t(a <= b) 返回 True。\n",
    "'''\n",
    "a = 10\n",
    "b = 20\n",
    "c = a == b\n",
    "print(a == b, c, type(c))\n",
    "print(a != b,  a > b, a < b, a >= b, a <= b)\n",
    "l1 = [11, 22, 33, 55]\n",
    "l2 = [11, 22, 32, 60]\n",
    "print(l1 == l2,l1 != l2,  l1 > l2, l1 < l2, l1 >= l2, l1 <= l2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "57bc7e17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30\n",
      "30\n",
      "-10\n",
      "18\n",
      "2.0\n",
      "1\n",
      "8\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "赋值运算符\n",
    "以下假设变量a为10，变量b为20：\n",
    "运算符\t描述\t实例\n",
    "=\t简单的赋值运算符\tc = a + b 将 a + b 的运算结果赋值为 c\n",
    "+=\t加法赋值运算符\tc += a 等效于 c = c + a\n",
    "-=\t减法赋值运算符\tc -= a 等效于 c = c - a\n",
    "*=\t乘法赋值运算符\tc *= a 等效于 c = c * a\n",
    "/=\t除法赋值运算符\tc /= a 等效于 c = c / a\n",
    "%=\t取模赋值运算符\tc %= a 等效于 c = c % a\n",
    "**=\t幂赋值运算符\tc **= a 等效于 c = c ** a\n",
    "//=\t取整除赋值运算符\tc //= a 等效于 c = c // a\n",
    "'''\n",
    "a = 10\n",
    "b = 20\n",
    "c = 0  # 定义变量c\n",
    "c = a + b  # 变量c赋值为 a+b\n",
    "print(c)\n",
    "a += b  # a = a + b\n",
    "print(a)\n",
    "a = 10\n",
    "a -= b\n",
    "print(a)\n",
    "a = 6\n",
    "b = 3\n",
    "a *= b\n",
    "print(a)\n",
    "a = 6\n",
    "a /= b\n",
    "print(a)\n",
    "a = 7\n",
    "a %= b\n",
    "print(a)\n",
    "a = 2\n",
    "a **= b\n",
    "print(a)\n",
    "a = 10\n",
    "a//=b\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "9a49fcba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1a <= b\n",
      "a<b or b<c\n",
      "a <= b\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "逻辑运算符\n",
    "以下假设变量 a 为 10, b为 20:\n",
    "运算符\t逻辑表达式\t描述\t实例\n",
    "and\tx and y\t布尔\"与\" - 如果 x 为 False，x and y 返回 False，否则它返回 y 的计算值。\t(a and b) 返回 20。\n",
    "or\tx or y\t布尔\"或\" - 如果 x 是非 0，它返回 x 的值，否则它返回 y 的计算值。\t(a or b) 返回 10。\n",
    "not\tnot x\t布尔\"非\" - 如果 x 为 True，返回 False 。如果 x 为 False，它返回 True。\tnot(a and b) 返回 False\n",
    "'''\n",
    "# for i in range(100):\n",
    "#  print(\"nihao 小吴\")\n",
    "a = 10\n",
    "b = 12\n",
    "c = 20\n",
    "if a > b and b < c:\n",
    "    print(\"a > b and b < c\")\n",
    "elif a <= b:\n",
    "    print(\"1a <= b\")\n",
    "else:\n",
    "    print(\"2b >= c\")\n",
    "\n",
    "    \n",
    "if a < b or b < c:\n",
    "    print('a<b or b<c')\n",
    "else:\n",
    "    print('a>=b and b>=c')\n",
    "    \n",
    "if not a > b:\n",
    "    print(\"a <= b\")\n",
    "else:\n",
    "    print(\"a > b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e98de15b",
   "metadata": {},
   "source": [
    "* 位运算符法则：\n",
    "\n",
    "符号     | 描述 | 规则\n",
    "-------- | :-----: | -----\n",
    "&  | 与 | 两位都为1，结果为1\n",
    "\\|  | 或 | 有一位为1，结果为一\n",
    "~  | 非 | ~0 = 1， ~1 = 0\n",
    "^  | 亦或 | 两位不相同，结果为1\n",
    "<< | 左移 | 二进位全部向左移动若干位，高位丢弃，低位补0\n",
    ">> | 右移 | 二进位全部向右移动若干位，对于无符号，高位补0，有符号数处理不一致"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "74a52671",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n",
      "<class 'int'>\n",
      "2\n",
      "15\n",
      "ccc 4294967292 0b11111111111111111111111111111100 <class 'int'>\n",
      "-0b100 -4 <class 'int'>\n",
      "13\n",
      "zuo 6\n",
      "11 5\n",
      "c==cc 0b10011\n",
      "0b11 <class 'str'>\n",
      "0b1110 <class 'str'>\n",
      "3 <class 'int'>\n",
      "14 <class 'int'>\n",
      "<built-in function bin>\n"
     ]
    }
   ],
   "source": [
    "#int最高有32位\n",
    "a = 0b1100000000000000000  # 0 + 2**1 + 2**0\n",
    "b = 0b1110  # 0 + 2**3 + 2**2 + 2**1 + 0\n",
    "c = -1\n",
    "print(type(c))\n",
    "c = 1\n",
    "print(type(c))\n",
    "\n",
    "#0b111111111111...;32 -> 31 + 30 + 0\n",
    "#0b111111111111...; 32 -> 30 + 20 + +0 (-)\n",
    "#0b01111111111....; 31 -> 30 + 29 + 0\n",
    "c = a & b # 0b10,2\n",
    "print(c)\n",
    "c = a|b #1111,15\n",
    "print(c)\n",
    "c = ~a #\n",
    "ccc = 0b11111111111111111111111111111100\n",
    "print(\"ccc\", ccc, bin(ccc),type(ccc))\n",
    "print(bin(c),c, type(c))\n",
    "#print(bin(b), type(bin(b)))\n",
    "c = a^b #1101,13\n",
    "print(c)\n",
    "c = a<<1 #110,6,左移1位相当于*2，2位相当于*4，3位相当于*8\n",
    "print('zuo',c)\n",
    "a = 0b1011 #末尾是0，右移1位相当于/2，末尾是1，右移1位相当于/2-0.5\n",
    "c = a>>1 #0b101,5\n",
    "print(a,c)\n",
    "a = 3\n",
    "b = 14\n",
    "c = 19  # ob +\n",
    "cc = '0b10011'\n",
    "if bin(c) == cc:\n",
    "    print('c==cc',cc)\n",
    "else:\n",
    "    print('c!=cc')\n",
    "print(bin(a), type(bin(a)))\n",
    "print(bin(b), type(bin(b)))\n",
    "print(a, type(a))\n",
    "print(b, type(b))\n",
    "print(bin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "8788fcc3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a exist list\n",
      "a exist list\n",
      "a exist list\n",
      "a exist list\n",
      "a exist list\n",
      "a exist list\n",
      "[1, 2, 3] exist l\n",
      "11\n",
      "123\n",
      "22\n",
      "33\n",
      "44\n",
      "44 exist list\n",
      "[1, 2, 3]\n",
      "44 doesnot exist l\n",
      "44 doesnot exist l\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "成员运算符\n",
    "运算符\t描述\t实例 \n",
    "in\t如果在指定的序列中找到值返回True，否则返回False。\tx 在 y序列中 , 如果x在y序列中返回True。\n",
    "not in\t如果在指定的序列中没有找到值返回True，否则返回False。\tx 不在 y序列中 , 如果x不在y序列中返回True\n",
    "'''\n",
    "l = [11, 123, 22, 33, 44]\n",
    "a = 123\n",
    "if a in l:\n",
    "    print(\"a exist list\")\n",
    "for a in l:\n",
    "    print(\"a exist list\")\n",
    "li = [1, 2, 3]\n",
    "l.append(li)\n",
    "if li in l:\n",
    "    print(li, 'exist l')\n",
    "else:\n",
    "    print(li, 'doesnot exist l')\n",
    "\n",
    "for i in l:\n",
    "    print(i)\n",
    "    if a == i:\n",
    "        print(a, \"exist list\")\n",
    "s = {1, 2, 3}\n",
    "if not a in s:\n",
    "    print(a, 'doesnot exist l')\n",
    "s = {1, 2, 3}\n",
    "if  a not in s:\n",
    "    print(a, 'doesnot exist l')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "dc0511cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "yes\n",
      "yeah\n",
      "NO\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "身份运算符\n",
    "身份运算符用于比较两个对象的存储单元\n",
    "运算符\t描述\t实例\n",
    "is\tis是判断两个标识符是不是引用自一个对象\tx is y, 如果 id(x) 等于 id(y) , is 返回结果 1\n",
    "is not\tis not是判断两个标识符是不是引用自不同对象\tx is not y, 如果 id(x) 不等于 id(y). is not 返回结果 1\n",
    "'''\n",
    "a = 1\n",
    "b = 1\n",
    "if a == b:\n",
    "    print('yes')\n",
    "if a is b:\n",
    "    print('yeah')\n",
    "a = [1, 2, 3]\n",
    "b = [1, 2, 3]\n",
    "if a != b:\n",
    "    print('no')\n",
    "if a is not b:\n",
    "    print('NO')  # 这里is not是说a b是否是同一对象，此处虽然相等，但是因为存储的地方不同，不能被认为是同一个东西\n",
    "a = ('e', 'd', 'f')\n",
    "b = a\n",
    "if a is not b:\n",
    "    print('no1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "a8ca3c6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\n运算符优先级\\n\\n以下表格列出了从最高到最低优先级的所有运算符：\\n\\n运算符\\t描述\\n**\\t指数 (最高优先级)\\n~ + -\\t按位翻转, 一元加号和减号 (最后两个的方法名为 +@ 和 -@)\\n* / % //\\t乘，除，取模和取整除\\n+ -\\t加法减法\\n>> <<\\t右移，左移运算符\\n&\\t位 'AND'\\n^ |\\t位运算符\\n<= < > >=\\t比较运算符\\n<> == !=\\t等于运算符\\n= %= /= //= -= += *= **=\\t赋值运算符\\nis is not\\t身份运算符\\nin not in\\t成员运算符\\nnot or and\\t逻辑运算符\\n\""
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "运算符优先级\n",
    "\n",
    "以下表格列出了从最高到最低优先级的所有运算符：\n",
    "\n",
    "运算符\t描述\n",
    "**\t指数 (最高优先级)\n",
    "~ + -\t按位翻转, 一元加号和减号 (最后两个的方法名为 +@ 和 -@)\n",
    "* / % //\t乘，除，取模和取整除\n",
    "+ -\t加法减法\n",
    ">> <<\t右移，左移运算符\n",
    "&\t位 'AND'\n",
    "^ |\t位运算符\n",
    "<= < > >=\t比较运算符\n",
    "<> == !=\t等于运算符\n",
    "= %= /= //= -= += *= **=\t赋值运算符\n",
    "is is not\t身份运算符\n",
    "in not in\t成员运算符\n",
    "not or and\t逻辑运算符\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43afdcce",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
